/**
 * Created by hxpeng on 2017/3/24.
 */
(function () {
    'use strict';

    angular.module('App.pages.class')
        .controller('MemberEditCtrl', MemberEditCtrl);

    function MemberEditCtrl($scope,MemberModel,LoginAccountAuth,AppUtils) {
        var vm = this;
        vm.memberVo = {};
        vm.loginAccountVo = {};

        LoginAccountAuth.getAccount().then(function(data){
            vm.loginAccountVo = data;
            MemberModel.getMemberInfo({id:data.memberId}).$promise.then(function(response){
                if(!AppUtils.isUndefinedOrNull(response.memberInfo)){
                    vm.memberVo = response.memberInfo;
                    vm.memberVo.memberBirthday = new Date(vm.memberVo.memberBirthday);
                }else {
                    AppUtils.showTipsTop("未查询到成员信息！");
                }
            })
        })

        $scope.commit = function(){
            MemberModel.saveParentMemberInfo(vm.memberVo).$promise.then(function(response){
                var result = response.result;
                if(!AppUtils.isUndefinedOrNull(result) && result == 'success'){
                    AppUtils.showTipsTop("保存成员信息成功！");
                }else{
                    AppUtils.showTipsTop("保存失败！");
                }
            });
        }

    }
})();
